﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.UC.订单一览新.辅料.service;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.订单一览新.辅料.辅料重构
{
    public partial class Form辅料重构 : DevExpress.XtraEditors.XtraForm
    {
        private List<SubMaterialSpuDao> subMaterialSpuDaos = new List<SubMaterialSpuDao>();
        public Form辅料重构()
        {
            InitializeComponent();
            this.刷新SPU();
        }

        private void simpleButton新增_Click(object sender, EventArgs e)
        {
            new Form辅料SPU维护().ShowDialog();
            this.刷新SPU();
        }

        private void 刷新SPU()
        {
            this.subMaterialSpuDaos = 辅料Service.getSubMaterialSpuAll();
            this.gridControl类别下辅料一览.DataSource = this.subMaterialSpuDaos;
            this.gridView类别下辅料一览.RefreshData();
            this.gridView1.RefreshData();
        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                String subMaterialCode = FunctionHelper.GetgridViewValue(this.gridView类别下辅料一览, this.gridView类别下辅料一览.FocusedRowHandle, "subMaterialCode");
                foreach (SubMaterialSpuDao item in this.subMaterialSpuDaos)
                {
                    if (subMaterialCode.Equals(item.subMaterialCode))
                    {
                        new Form辅料SPU维护(item).ShowDialog();
                        break;
                    }
                }
                this.刷新SPU();
            }
            catch { }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出Excel";
            fileDialog.Filter = "Excel文件(*.xls)|*.xls";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                this.gridControl类别下辅料一览.ExportToXls(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void 维护对应SKUToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                String subMaterialCode = FunctionHelper.GetgridViewValue(this.gridView类别下辅料一览, this.gridView类别下辅料一览.FocusedRowHandle, "subMaterialCode");
                foreach (SubMaterialSpuDao item in this.subMaterialSpuDaos)
                {
                    if (subMaterialCode.Equals(item.subMaterialCode))
                    {
                        new Form辅料SKU维护(
                            item.subMaterialTypeId, 
                            item.subMaterialType, 
                            item.subMaterialCode, 
                            item.subMaterialName, 
                            item.subMaterialSupplier
                            ).ShowDialog();
                        break;
                    }
                }
                this.刷新SPU();
            }
            catch { }
        }

        private void 辅料图片ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                String subMaterialCode = FunctionHelper.GetgridViewValue(this.gridView类别下辅料一览, this.gridView类别下辅料一览.FocusedRowHandle, "subMaterialCode");
                String subMaterialName = FunctionHelper.GetgridViewValue(this.gridView类别下辅料一览, this.gridView类别下辅料一览.FocusedRowHandle, "subMaterialName");
                new Form辅料图片(subMaterialCode,subMaterialName).ShowDialog();
            }
            catch { }
        }

        private void 导出excelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出辅料";
            fileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                this.gridView类别下辅料一览.ExportToXlsx(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("文件已保存至" + fileDialog.FileName, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}